<template>
  <div class="app-container kuan">
    <el-form ref="form" :model="query" :rules="rules" label-width="180px">
      <el-form-item label="结束时间" prop="endTime">
        <el-input-number v-model="query.endTime" placeholder="" />
      </el-form-item>
      <el-form-item label="定量结算时间(星期1-7)" prop="settleTime">
        <el-input-number v-model="query.settleTime" placeholder="" />
      </el-form-item>
      <el-form-item label="报量提前周" prop="doseTime">
        <el-input-number v-model="query.doseTime" placeholder="" />
      </el-form-item>
      <el-form-item label="价格上浮" prop="priceUp">
        <el-input v-model="query.priceUp" placeholder="" />
      </el-form-item>
      <el-form-item label="是否开启报量">
        <el-switch v-model="doseFlag" active-text="开启" inactive-text="关闭">
        </el-switch>
      </el-form-item>
      <el-form-item label="公告">
        <el-input v-model="query.content" type="textarea"  placeholder="" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="submit">保存</el-button>
        <!-- <el-button type="danger" size="mini" @click="close">关闭</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>
  
  <script>
import { listSet, addSet } from "@/api/system/setting";

export default {
  data() {
    const equalToPassword = (rule, value, callback) => {
      if (this.user.newPassword !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
    return {
      query: {
        endTime: undefined, //价格上浮
        settleTime: undefined, //价格上浮
        priceUp: undefined, //价格上浮
        doseTime: undefined, //报量提前周
        doseFlag: 0, //是否开启报量 0开启 1不开启
        content:undefined
      },
      doseFlag: true,
      // 表单校验
      rules: {
        oldPassword: [
          { required: true, message: "旧密码不能为空", trigger: "blur" },
        ],
        newPassword: [
          { required: true, message: "新密码不能为空", trigger: "blur" },
          {
            min: 6,
            max: 20,
            message: "长度在 6 到 20 个字符",
            trigger: "blur",
          },
          {
            pattern: /^[^<>"'|\\]+$/,
            message: "不能包含非法字符：< > \" ' \\ |",
            trigger: "blur",
          },
        ],
        confirmPassword: [
          { required: true, message: "确认密码不能为空", trigger: "blur" },
          { required: true, validator: equalToPassword, trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.show();
  },
  methods: {
    show() {
      listSet({
        pageNum: 1,
        pageSize: 1,
      }).then((response) => {
        this.query = response.rows[0];
        if (this.query.doseFlag == 0) {
          this.doseFlag = true;
        } else {
          this.doseFlag = false;
        }
      });
    },
    submit() {
      var qus = JSON.stringify(this.query);
      var data = JSON.parse(qus);
      if (this.doseFlag) {
        data.doseFlag = 0;
      } else {
        data.doseFlag = 1;
      }
      addSet(data).then((response) => {
        this.$modal.msgSuccess("保存成功");
        this.show();
      });
    },
    close() {
      this.$tab.closePage();
    },
  },
};
</script>


<style rel="stylesheet/scss" lang="scss">
.kuan {
  width: 500px;
  input,
  .el-input,
  .el-input-number--medium {
    width: 100%;
  }
}
</style>

  